package logic

import (
	"api/model/mysql"
	"context"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AminListHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAminListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AminListHouseLogic {
	return &AminListHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AminListHouseLogic) AminListHouse(in *house.AminListHouseRequest) (*house.AminListHouseResponse, error) {
	// todo: add your logic here and delete this line

	var houses []mysql.House
	mysql.DB.Debug().Where("house_status=?", in.HouseStatus).Find(&houses)

	var lists []*house.AminListHouse

	for _, m := range houses {
		listHouse := house.AminListHouse{
			HouseCity:    m.HouseCity,
			HouseAddress: m.HouseAddress,
			HouseBuild:   m.HouseBuild,
			HouseFloor:   m.HouseFloor,
			HouseArea:    int64(m.HouseArea),
			HousePrice:   float32(m.HousePrice),
			HouseAuthor:  m.HouseAuthor,
			HouseStatus:  int64(m.HouseStatus),
		}
		lists = append(lists, &listHouse)
	}

	return &house.AminListHouseResponse{
		List: lists,
	}, nil
}
